package com.wc.alorithm_blue_bridge._思维.Q3776;

import java.util.Scanner;

/**
 * @Author congge
 * @Date 2023/11/22 11:51
 * @description 无尽的石头
 * https://www.lanqiao.cn/problems/3766/learning/?page=1&first_category_id=1
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();

        while (t-- > 0) {
            int num = sc.nextInt();
            int curPos = 1;
            int ans = 0;
            while (curPos < num) {
                curPos += calSum(curPos);
                ans++;
            }
            if (curPos == num) {
                System.out.println(ans);
            } else {
                System.out.println(-1);
            }
        }
    }

    static int calSum(int val) {
        if (val < 10) {
            return val;
        }
        int ans = 0;
        while (val != 0) {
            ans += val % 10;
            val /= 10;
        }

        return ans;
    }
}
